home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / StringUtils.java < prev    next >
Text File  |  1998-09-08  |  6KB  |  246 lines

  1. package com.symantec.itools.lang;
  2.  
  3.  
  4. /**
  5.  * @author Symantec Internet Tools Division
  6.  * @version 1.0
  7.  * @since VCafe 3.0
  8.  */
  9.  
  10. public class StringUtils
  11. {
  12.     protected StringUtils()
  13.     {
  14.         throw new IllegalInstantiationError(StringUtils.class);
  15.     }
  16.  
  17.     /**
  18.      * @param str1 TODO
  19.      * @param str2 TODO
  20.      * @since VCafe 3.0
  21.      */
  22.  
  23.     public static int compareToIgnoreCase(String str1, String str2)
  24.     {
  25.         return (str1.toLowerCase().compareTo(str2.toLowerCase()));
  26.     }
  27.  
  28.     /**
  29.      * @param str TODO
  30.      * @param suffix TODO
  31.      * @since VCafe 3.0
  32.      */
  33.  
  34.     public static boolean endsWithIgnoreCase(String str, String suffix)
  35.     {
  36.         return (str.toLowerCase().endsWith(suffix.toLowerCase()));
  37.     }
  38.  
  39.     /**
  40.      * @param str TODO
  41.      * @param find TODO
  42.      * @since VCafe 3.0
  43.      */
  44.  
  45.     public static int indexOfIgnoreCase(String str, int find)
  46.     {
  47.         return (str.toLowerCase().indexOf(Character.toLowerCase((char)find)));
  48.     }
  49.  
  50.     /**
  51.      * @param str TODO
  52.      * @param find TODO
  53.      * @param start TODO
  54.      * @since VCafe 3.0
  55.      */
  56.  
  57.     public static int indexOfIgnoreCase(String str, int find, int start)
  58.     {
  59.         return (str.toLowerCase().indexOf(Character.toLowerCase((char)find), start));
  60.     }
  61.  
  62.     /**
  63.      * @param str TODO
  64.      * @param find TODO
  65.      * @since VCafe 3.0
  66.      */
  67.  
  68.     public static int indexOfIgnoreCase(String str, String find)
  69.     {
  70.         return (str.toLowerCase().indexOf(find.toLowerCase()));
  71.     }
  72.  
  73.     /**
  74.      * @param str TODO
  75.      * @param find TODO
  76.      * @param start TODO
  77.      * @since VCafe 3.0
  78.      */
  79.  
  80.     public static int indexOfIgnoreCase(String str, String find, int start)
  81.     {
  82.         return (str.toLowerCase().indexOf(find.toLowerCase(), start));
  83.     }
  84.  
  85.     /**
  86.      * @param str TODO
  87.      * @param find TODO
  88.      * @since VCafe 3.0
  89.      */
  90.  
  91.     public static int lastIndexOfIgnoreCase(String str, int find)
  92.     {
  93.         return (str.toLowerCase().lastIndexOf(Character.toLowerCase((char)find)));
  94.     }
  95.  
  96.     /**
  97.      * @param str TODO
  98.      * @param find TODO
  99.      * @param start TODO
  100.      * @since VCafe 3.0
  101.      */
  102.  
  103.     public static int lastIndexOfIgnoreCase(String str, int find, int start)
  104.     {
  105.         return (str.toLowerCase().lastIndexOf(Character.toLowerCase((char)find), start));
  106.     }
  107.  
  108.     /**
  109.      * @param str TODO
  110.      * @param find TODO
  111.      * @since VCafe 3.0
  112.      */
  113.  
  114.     public static int lastIndexOfIgnoreCase(String str, String find)
  115.     {
  116.         return (str.toLowerCase().lastIndexOf(find.toLowerCase()));
  117.     }
  118.  
  119.     /**
  120.      * @param str TODO
  121.      * @param find TODO
  122.      * @param start TODO
  123.      * @since VCafe 3.0
  124.      */
  125.  
  126.     public static int lastIndexOfIgnoreCase(String str, String find, int start)
  127.     {
  128.         return (str.toLowerCase().lastIndexOf(find.toLowerCase(), start));
  129.     }
  130.  
  131.     /**
  132.      * @param str TODO
  133.      * @param ch TODO
  134.      * @since VCafe 3.0
  135.      */
  136.  
  137.     public static int occurencesOf(String str, char ch)
  138.     {
  139.         char[] s;
  140.         int    count;
  141.  
  142.         s = new char[str.length()];
  143.         str.getChars(0, s.length, s, 0);
  144.         count = 0;
  145.  
  146.         for(int i = 0; i < s.length; i++)
  147.         {
  148.             if(s[i] == ch)
  149.             {
  150.                 count++;
  151.             }
  152.         }
  153.  
  154.         return (count);
  155.     }
  156.  
  157.     /**
  158.      * @param str TODO
  159.      * @param ch TODO
  160.      * @since VCafe 3.0
  161.      */
  162.  
  163.     public static int occurencesOfIgnoreCase(String str, char ch)
  164.     {
  165.         return (occurencesOf(str.toLowerCase(), Character.toLowerCase(ch)));
  166.     }
  167.  
  168.     /**
  169.      * @param str TODO
  170.      * @param oldChars TODO
  171.      * @param newChars TODO
  172.      * @since VCafe 3.0
  173.      */
  174.  
  175.     public static String replace(String str, String oldChars, String newChars)
  176.     {
  177.         int pos;
  178.  
  179.         pos = str.indexOf(oldChars);
  180.  
  181.         while(pos > -1)
  182.         {
  183.             String firstPart;
  184.             String lastPart;
  185.  
  186.             firstPart = str.substring(0, pos);
  187.             lastPart  = str.substring(pos + oldChars.length(), str.length());
  188.             str       = firstPart + newChars + lastPart;
  189.             pos       = str.indexOf(oldChars);
  190.         }
  191.  
  192.         return (str);
  193.     }
  194.  
  195.     /**
  196.      * @param str TODO
  197.      * @param oldChars TODO
  198.      * @param newChars TODO
  199.      * @since VCafe 3.0
  200.      */
  201.  
  202.     public static String replaceIgnoreCase(String str, String oldChars, String newChars)
  203.     {
  204.         String lowerStr;
  205.         int    pos;
  206.  
  207.         lowerStr = str.toLowerCase();
  208.         pos      = lowerStr.indexOf(oldChars);
  209.  
  210.         while(pos > -1)
  211.         {
  212.             String firstPart;
  213.             String lastPart;
  214.  
  215.             firstPart = str.substring(0, pos);
  216.             lastPart  = str.substring(pos + oldChars.length(), str.length());
  217.             str       = firstPart + newChars + lastPart;
  218.             pos       = lowerStr.indexOf(oldChars);
  219.         }
  220.  
  221.         return (str);
  222.     }
  223.  
  224.     /**
  225.      * @param str TODO
  226.      * @param prefix TODO
  227.      * @since VCafe 3.0
  228.      */
  229.  
  230.     public static boolean startsWithIgnoreCase(String str, String prefix)
  231.     {
  232.         return (str.toLowerCase().startsWith(prefix.toLowerCase()));
  233.     }
  234.  
  235.     /**
  236.      * @param str TODO
  237.      * @param prefix TODO
  238.      * @param start TODO
  239.      * @since VCafe 3.0
  240.      */
  241.  
  242.     public static boolean startsWithIgnoreCase(String str, String prefix, int start)
  243.     {
  244.         return (str.toLowerCase().startsWith(prefix.toLowerCase(), start));
  245.     }
  246. }